From a615a7e531bee77743cdfe15931a251d56b37228 Mon Sep 17 00:00:00 2001 From: Abhishek Chanda Date: Tue, 11 Aug 2015 23:21:06 -0700 Subject: [PATCH] Improve the error message when a crate cannot be found Closes #1892 --- src/cargo/ops/registry.rs | 6 +++--- src/crates-io/lib.rs | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index ee2e78f52..57ea235d7 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -281,7 +281,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> { try!(config.shell().status("Owner", format!("adding `{:?}` to `{}`", v, name))); try!(registry.add_owners(&name, &v).map_err(|e| { - human(format!("failed to add owners: {}", e)) + human(format!("failed to add owners to crate {}: {}", name, e)) })); } None => {} @@ -293,7 +293,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> { try!(config.shell().status("Owner", format!("removing `{:?}` from `{}`", v, name))); try!(registry.remove_owners(&name, &v).map_err(|e| { - human(format!("failed to remove owners: {}", e)) + human(format!("failed to remove owners from crate {}: {}", name, e)) })); } None => {} @@ -301,7 +301,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> { if opts.list { let owners = try!(registry.list_owners(&name).map_err(|e| { - human(format!("failed to list owners: {}", e)) + human(format!("failed to list owners of crate {}: {}", name, e)) })); for owner in owners.iter() { print!("{}", owner.login); diff --git a/src/crates-io/lib.rs b/src/crates-io/lib.rs index 6b6836ff6..ea19883be 100644 --- a/src/crates-io/lib.rs +++ b/src/crates-io/lib.rs @@ -36,6 +36,7 @@ pub enum Error { Unauthorized, TokenMissing, Io(io::Error), + NotFound, } #[derive(RustcDecodable)] @@ -231,6 +232,7 @@ fn handle(response: result::Result) 0 => {} // file upload url sometimes 200 => {} 403 => return Err(Error::Unauthorized), + 404 => return Err(Error::NotFound), _ => return Err(Error::NotOkResponse(response)) } @@ -263,6 +265,7 @@ impl fmt::Display for Error { Error::Unauthorized => write!(f, "unauthorized API access"), Error::TokenMissing => write!(f, "no upload token found, please run `cargo login`"), Error::Io(ref e) => write!(f, "io error: {}", e), + Error::NotFound => write!(f, "cannot find crate"), } } } -- 2.30.2